package com.ldcc.report_system.util.http.Interceptor;

import android.content.Context;


import com.ldcc.report_system.ReportApplication;
import com.ldcc.report_system.ApplicationConfig;
import com.ldcc.report_system.util.SharedPreferencesUtils;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * @author wwj[yeshengkele@lookout.com]
 * @description okHttp 请求头拦截器
 */
public class HeaderInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Context context = ReportApplication.getContext();
        String token = (String) SharedPreferencesUtils.getParam(context, ApplicationConfig.USER_TOKEN_KEY, "");
        assert token != null;
        Request request = chain.request()
                .newBuilder()
                // 添加头信息
                .addHeader(ApplicationConfig.SERVER_TOKEN_HEADER, token)
                .addHeader("Content-Type", "application/json;charSet=UTF-8")
                .build();
        return chain.proceed(request);
    }

}
